<?php
namespace App\Services\Fund;

use App\Services\Fund\IntegralDistribute\IntegralDistributeLogic;
use App\Services\User\Token;
use App\Services\User\App;
use App\Services\Manage\Api;
use App\Services\User\User;
//use Illuminate\Support\Facades\Request;

/**
 * 积分
 * Class IntegralDistribute
 * @package App\Services\Fund
 */
class IntegralDistribute
{

    /*添加资金派发积分的记录*/
     public function add($data): array
    {
        $data = Api::addAppId($data);
        $token = (new Token())->hGetAll($data['token']);
        $data['system_user_name'] = $token['res']['name'];
        if($data['integral'] != 1){
            return verify_err(null, '设置规则必须为多少资产派发一个积分');
        }
        return (new IntegralDistributeLogic())->add($data);
    }


    /*获取某应用下的最新一条积分派发记录*/
    public function getOneNew($data): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>0]);
        return $this->stepRun($data, 'getOneNew', '', $this->integralDistributeValidate, $this->integralDistributeLogic);
    }

    /*后台获取积分派发记录列表*/
    public function list($data): array 
    {
        $app_key = config('tpproject.yayi_admin_app_key');
        $find = (new App())->find(['app_key'=>$app_key]);
        if($find['res']['status'] != SUCCESS_STATUS){
            return $find ;
        }
        $data['app_id'] = $find['res']['id'];
        $data = init_array($data,['app_id'=>0, 'page'=>1, 'listRows'=>15]);
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        ValidateIntegralDistribute::checkValidate($data, ['app_id']);
        return (new IntegralDistributeLogic())->list($data);
    }
    /*根据搜索条件获取派发记录列表（分页）*/
   /* public function getDistributePageList($data): array 
    {
        $data = init_array($data,['distribute_date'=>'', 'keywords'=>'', 'status'=>'','certificate_id'=>'', 'page'=>1, 'listRows'=>15]);
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
       // ValidateIntegralDistribute::checkValidate($data, ['app_id']);
        return (new IntegralDistributeLogic())->getDistributePageList($data);

      
    }
*/
}